#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
vector<int>v,l,r;
bool f=1;
void dfs(int c,int h)
{
	if(f==1)return ;
	if(c==n)
	{
		f=1;
		for(int i=1;i<=n;i++)
		{
			cout<<v[i]<<" ";
		}
		cout<<endl;
		return ;
	}
	if(v[c+1]==1&&h+1<=r[c+1]&&h+1>=l[c+1])dfs(c+1,h+1);
	else if(v[c+1]==0&&h<=r[c+1]&&h>=l[c+1])dfs(c+1,h);
	else if(v[c+1]==-1)
	{
		v[c+1]=1;
		if(v[c+1]==1&&h+1<=r[c+1]&&h+1>=l[c+1])dfs(c+1,h+1);
		v[c+1]=0;
		if(v[c+1]==0&&h<=r[c+1]&&h>=l[c+1])dfs(c+1,h);
		v[c+1]=-1;
	}
	else return;
}
void solve()
{
	f=1;
	cin>>n;
	v=l=r=vector<int>(n+1);
	for(int i=1;i<=n;i++)
	{
		cin>>v[i];
	}
	// for(int i=1;i<=n;i++)
	// {
	// 	cin>>l[i]>>r[i];
	// }
	for (int i = 1; i <= n; i++) 
	{
        cin >> l[i] >> r[i];
        l[i] = std::max(l[i], l[i - 1] + (v[i] == 1 ? 1 : 0));
        r[i] = std::min(r[i], r[i - 1] + (v[i] == 0 ? 0 : 1));
        if (l[i] > r[i]) {
            f = false;
        }
    }
	if(!f)
	{
		cout<<-1<<endl;
		return ;
	}
	f=0;
	dfs(0,0);
	if(!f)cout<<-1<<endl;
}
signed main()
{
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	int T=1;
	cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
}